package com.example.schooljava.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.schooljava.pojo.entity.Class;
import com.example.schooljava.pojo.entity.ClassCurr;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.schooljava.pojo.entity.Curriculum;
import com.example.schooljava.pojo.entity.Teacher;
import com.example.schooljava.pojo.bo.ClassCurrBO;
import com.example.schooljava.pojo.vo.RelationVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LDH
 * @since 2022/08/13
 */
@Mapper
public interface ClassCurrMapper extends BaseMapper<ClassCurr> {
    @Select("SELECT curriculum.id id,curriculum.name name\n" +
            "FROM class_curr,curriculum\n" +
            "WHERE classid=#{classid} AND currid=curriculum.id")
    List<Curriculum> getCurrOfClass(@Param("classid") Long classid);

    IPage<RelationVO> getRelation(Page<RelationVO> page, @Param("q") ClassCurrBO classCurrBO);

    @Select("SELECT grade FROM class GROUP BY grade ORDER BY grade")
    List<Integer> getGrade();

    @Select("SELECT id,name FROM class WHERE grade=#{grade}")
    List<Class> getClassName(@Param("grade") Integer grade);

    @Select("SELECT id, name FROM curriculum WHERE grade=#{grade}")
    List<Curriculum> getCurrOfGrade(@Param("grade") Integer grade);

    @Select("SELECT tno,teacher.name \n" +
            "FROM class_curr, teacher, curriculum \n" +
            "WHERE teacherid=tno AND curriculum.id=currid AND curriculum.name=#{curriculum} \n" +
            "UNION\n" +
            "SELECT tno,teacher.name \n" +
            "FROM class_curr RIGHT JOIN teacher ON tno=teacherid \n" +
            "WHERE teacherid IS NULL")
    List<Teacher> getTeacherOfCurr(@Param("curriculum") String curriculum);
}
